import { BASE_URL } from "@/api/api";

// 歌曲封面地址
export function getCoverUrl(
    username: string,
    subsonicToken: string,
    salt: string,
    songId: string
): string {
    const url = new URL(BASE_URL + "rest/getCoverArt");

    // 添加查询参数
    const params = {
        u: username, // username
        t: subsonicToken, // subsonic-token
        s: salt, // salt
        f: "json", // 固定值, json
        v: "1.8.0", // 固定值, 1.8.0
        c: "NavidromeUI", // 固定值, NavidromeUI
        id: songId, // 歌曲id
        _: new Date().getTime() + "",
        size: "300",
    };

    for (const [key, value] of Object.entries(params)) {
        url.searchParams.append(key, value);
    }

    return url.toString();
}

// 歌曲播放流地址
export function getSongStreamUrl(
    username: string,
    subsonicToken: string,
    salt: string,
    songId: string
): string {
    const url = new URL(BASE_URL + "rest/stream");

    const params = {
        u: username,
        t: subsonicToken,
        s: salt,
        f: "json",
        v: "1.8.0",
        c: "NavidromeUI",
        id: songId,
        _: new Date().getTime() + "",
    };

    for (const [key, value] of Object.entries(params)) {
        url.searchParams.append(key, value);
    }

    return url.toString();
}
